/**
 * MERARY — fluid layout + выравнивание 100%/125% Windows на Full HD.
 * Эталон: viewport ~1536 CSS px (Windows 125% на 1920×1080).
 * При 100% (1920 CSS px) site-viewport.js масштабирует body через --site-scale.
 */

:root {
  --layout-ref: 96rem; /* 1536px */
  --gutter: 3rem;
  --container-max: min(120rem, calc(100vw - 2 * var(--gutter)));
  --design-max: var(--container-max);
  --section-space: 4rem;
  --header-height: 4.75rem;
  --base-font: 0.875rem;
  --site-scale: 1;

  /* rem, не vw — одинаково при 1536 и 1920 CSS px внутри контейнера */
  --hero-min-h: 32.5rem;
  --hero-photo-max: 37.5rem;
  --hero-title-size: 3.25rem;
  --cx-hero-min-h: 28.75rem;
  --cx-hero-photo-max: 26.25rem;
  --cx-card-img-h: 23.75rem;

  --logo-h: 3.625rem;
  --logo-name: 1.75rem;
  --logo-tag: 0.875rem;
  --nav-fs: 0.875rem;
  --nav-gap: 1.75rem;
  --icon-btn: 2.5rem;
}

@media (max-width: 63.9375rem) {
  :root {
    --gutter: clamp(1rem, 3vw, 1.75rem);
    --container-max: calc(100vw - 2 * var(--gutter));
    --design-max: var(--container-max);
  }
}

/* 1200–1299px: шесть пунктов меню + иконки не помещаются при зазоре 28px — колонка действий сжимается
   до ~84px, и «О нас» заезжает на иконки. Зазор меню плавно сжимается (10px на 1200 → 28px к ~1290)
   и оставляет ≥12px до иконок даже на странице товара (самый широкий чип города). */
@media (min-width: 75rem) and (max-width: 81.25rem) {
  :root {
    --nav-gap: clamp(10px, calc(10px + (100vw - 1193px) * 0.2), 28px);
  }
}

@media (max-width: 47.9375rem) {
  :root {
    --gutter: 1rem;
    --base-font: 0.8125rem;
    --header-height: 4.25rem;
    --logo-h: 3rem;
    --logo-name: 1.375rem;
    --logo-tag: 0.75rem;
    --hero-min-h: 23.75rem;
    --hero-photo-max: 22.5rem;
    --hero-title-size: 2.25rem;
    --cx-card-img-h: 18.75rem;
  }
}

html {
  font-size: 100%;
  max-width: 100%;
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  max-width: 100%;
  overflow-x: clip;
}

body:not(.premium-page):not(.premium-product-page) {
  font-size: var(--base-font);
}

/* ===== Единый контейнер: шапка = контент, на всю ширину минус gutter ===== */
.container,
.cart-shell,
.dashboard-shell,
.home-categories .container,
.hero-merary .container,
.footer .container,
.cx-container,
.header .container,
.section .container,
.top-bar .container {
  width: 100%;
  max-width: var(--container-max) !important;
  margin-left: auto !important;
  margin-right: auto !important;
  padding-left: var(--gutter) !important;
  padding-right: var(--gutter) !important;
  box-sizing: border-box;
}

body.product-exact,
body.cart-exact,
body.profile-exact,
body.catalog-exact {
  --container-max: min(120rem, calc(100vw - 2 * var(--gutter)));
  --design-max: var(--container-max);
}

@media (max-width: 63.9375rem) {
  body.product-exact,
  body.cart-exact,
  body.profile-exact,
  body.catalog-exact {
    --container-max: calc(100vw - 2 * var(--gutter));
    --design-max: var(--container-max);
  }
}

.category-section,
.category-grid,
.products-grid,
.mcatalog-grid {
  max-width: 100%;
}

.site-modal,
.promo-modal {
  max-width: min(53.75rem, calc(100vw - 2rem));
}

img,
picture,
video,
canvas,
svg {
  max-width: 100%;
}

.container img,
.product-grid img,
.cx-product-image img,
.merary-gallery__photo img,
.hero-merary__visual img,
.cx-hero-visual img {
  height: auto;
}

/* Перебиваем vw в home-merary на desktop — иначе масштаб пляшет */
@media (min-width: 64rem) {
  .hero-merary__body,
  .hero-merary__inner {
    min-height: var(--hero-min-h) !important;
  }

  .hero-merary__photo,
  .hero-merary__visual img {
    max-height: var(--hero-photo-max) !important;
    max-width: 100% !important;
  }

  .hero-merary__title {
    font-size: var(--hero-title-size) !important;
  }

  :is(body.catalog-exact, .cx-admin-stage, #bestsellers) .cx-hero-inner {
    min-height: var(--cx-hero-min-h) !important;
  }

  :is(body.catalog-exact, .cx-admin-stage, #bestsellers) .cx-hero-visual img {
    max-height: var(--cx-hero-photo-max) !important;
  }

  :is(body.catalog-exact, .cx-admin-stage, #bestsellers) .cx-product-image {
    height: var(--cx-card-img-h) !important;
    flex: 0 0 var(--cx-card-img-h) !important;
  }
}

/* ===== Шапка (tablet/desktop only — avoids mobile cascade conflict) ===== */
@media (min-width: 48rem) {
  .header .container {
    display: grid !important;
    grid-template-columns: auto auto minmax(0, 1fr) !important;
    align-items: center;
    gap: 1rem 1.25rem;
  }

  .header__left,
  .header .logo {
    justify-self: start;
    min-width: 0;
    max-width: none;
  }

  .header .nav,
  .header__center {
    justify-self: start;
    gap: var(--nav-gap) !important;
  }

  .header .nav {
    gap: var(--nav-gap) !important;
  }

  .header__actions {
    justify-self: end;
    gap: 1.25rem !important;
  }

  .header .nav__link {
    font-size: var(--nav-fs);
  }

  .header .logo:not(.merary-brand) {
    gap: 0.875rem;
  }

  .header .logo.merary-brand {
    gap: 14px !important;
    width: 212px;
    min-height: 62px;
    flex-shrink: 0;
  }

  .header .logo.merary-brand .logo__img {
    display: none !important;
  }

  .header .logo:not(.merary-brand) .logo__img,
  .header .logo:not(.merary-brand) .logo__img:not(.logo__mark) {
    height: var(--logo-h);
    width: auto;
  }

  .header .logo:not(.merary-brand) .logo__mark {
    height: var(--logo-h) !important;
  }

  .header .logo:not(.merary-brand) .logo__name {
    font-size: var(--logo-name) !important;
    letter-spacing: 0.08em !important;
    line-height: 1.05 !important;
  }

  .header .logo:not(.merary-brand) .logo__tagline {
    font-size: var(--logo-tag) !important;
    font-weight: 700 !important;
    letter-spacing: 0.34em !important;
    color: #6a525c !important;
    margin-top: 0.3rem !important;
    text-align: center !important;
    padding-right: 0.34em !important;
  }

  .header__icon {
    width: var(--icon-btn);
    height: var(--icon-btn);
  }

  .header__icon svg {
    width: 1.375rem;
    height: 1.375rem;
  }
}

/* Tablet header: 1024px–1199px (desktop >=1200px unchanged) */
@media (min-width: 64rem) and (max-width: 74.9375rem) {
  .header .container {
    gap: 0.75rem 1rem;
  }

  .header__left {
    min-width: 0;
    max-width: 100%;
    gap: clamp(8px, 1.2vw, 14px);
  }

  .header .logo.merary-brand {
    /* Нижняя граница = ширина содержимого (марка 64 + зазор 12 + название ≈115), иначе на 1024px название
       выходит за блок бренда и заходит на чип города. */
    width: clamp(192px, 17vw, 198px);
    min-height: 58px;
    gap: 12px !important;
  }

  .header .city-select {
    min-width: 0;
    flex-shrink: 1;
  }

  .header .city-select__btn {
    padding: 8px 10px;
  }

  .header .city-select__btn strong {
    min-width: 6ch;
    max-width: 9ch;
  }

  .header__center {
    min-width: 0;
    max-width: 100%;
  }

  .header .nav {
    min-width: 0;
    max-width: 100%;
    flex: 1 1 auto;
    gap: clamp(0.625rem, 1.1vw, 1.125rem) !important;
  }

  .header .nav__link {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: clamp(0.8125rem, 0.75rem + 0.25vw, 0.875rem);
  }

  .header__actions {
    gap: clamp(0.625rem, 1vw, 1.125rem) !important;
  }

  /* Помощь + О нас — последние два пункта в .nav (см. ensureSiteNav) */
  .header .nav > a.nav__link:nth-last-child(-n+2) {
    display: none;
  }
}

/* Responsive header v1: narrow row header 768px–1023px */
@media (min-width: 48rem) and (max-width: 63.9375rem) {
  .header .container {
    gap: 0.625rem 0.75rem;
  }

  .header__left {
    min-width: 0;
    max-width: 100%;
    gap: clamp(6px, 1vw, 12px);
  }

  .header .logo.merary-brand {
    width: clamp(158px, 22vw, 188px);
    min-height: 54px;
    gap: 10px !important;
  }

  .header .city-select {
    min-width: 0;
    flex-shrink: 1;
  }

  .header .city-select__btn {
    padding: 7px 9px;
    font-size: 11px;
  }

  .header .city-select__btn strong {
    min-width: 5ch;
    max-width: 8ch;
  }

  .header__center {
    min-width: 0;
    max-width: 100%;
  }

  .header .nav {
    min-width: 0;
    max-width: 100%;
    flex: 1 1 auto;
    gap: clamp(0.5rem, 1.4vw, 0.875rem) !important;
  }

  .header .nav__link {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: clamp(0.75rem, 0.68rem + 0.35vw, 0.8125rem);
  }

  .header__actions {
    gap: clamp(0.5rem, 1vw, 0.875rem) !important;
  }

  .header .nav > a.nav__link:nth-last-child(-n+2) {
    display: none;
  }
}

@media (min-width: 64rem) {
  body:not(.premium-page):not(.premium-product-page) .header {
    min-height: var(--header-height);
  }

  .hero-merary {
    padding: 1rem 0 0;
  }

  .hero-merary__card {
    border-radius: 2.5rem;
  }

  .hero-merary__body,
  .hero-merary__inner {
    gap: 1rem;
    padding: 3rem 2rem 0;
  }

  .hero-merary__copy-col {
    padding-left: 4rem;
    padding-bottom: 1.75rem;
    max-width: 28.75rem;
  }

  .hero-merary__photo,
  .hero-merary__visual img {
    width: 100%;
    object-fit: contain;
  }

  :is(body.catalog-exact, .cx-admin-stage, #bestsellers) .cx-hero {
    padding: 1rem 0 0;
  }

  :is(body.catalog-exact, .cx-admin-stage, #bestsellers) .cx-hero-card {
    border-radius: 2.5rem;
  }

  :is(body.catalog-exact, .cx-admin-stage, #bestsellers) .cx-hero-inner {
    gap: 1rem;
    padding: 2.5rem 2.5rem 2rem;
  }

  :is(body.catalog-exact, .cx-admin-stage, #bestsellers) .cx-hero-copy h1 {
    font-size: 3.6rem;
  }

  :is(body.catalog-exact, .cx-admin-stage, #bestsellers) .cx-product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}

/* ===== 100% Windows на Full HD → тот же вид, что при 125% (1536 CSS px) ===== */
html.site-scale-wide {
  overflow-x: hidden;
  background-color: #fdf3f5;
  background-image: url('../images/site-background.png');
  background-repeat: no-repeat;
  background-position: center top;
  background-size: cover;
  background-attachment: fixed;
  --container-max: calc(var(--layout-ref) - 2 * var(--gutter));
  --design-max: var(--container-max);
}

html.site-scale-wide body {
  width: auto;
  max-width: none;
  margin-left: 0;
  margin-right: 0;
  transform: none;
  min-height: auto;
  background: transparent;
}

html.site-scale-wide .site-scale-canvas {
  width: var(--layout-ref);
  max-width: var(--layout-ref);
  margin-left: auto;
  margin-right: auto;
  transform: scale(var(--site-scale, 1));
  transform-origin: top center;
  min-height: calc(100vh / var(--site-scale, 1));
  /* Page gradient stays on body::before (+ html letterbox) — not on tall scaled canvas */
  background: transparent !important;
}

html.site-scale-wide body.product-exact,
html.site-scale-wide body.cart-exact,
html.site-scale-wide body.profile-exact,
html.site-scale-wide body.catalog-exact {
  --container-max: calc(var(--layout-ref) - 2 * var(--gutter));
  --design-max: var(--container-max);
}

/* Premium Atelier: keep black stage on wide monitors (no home pink bg) */
html.site-scale-wide:has(body.premium-page),
html.site-scale-wide:has(body.premium-product-page) {
  background: #000 !important;
  background-image: none !important;
}

html.site-scale-wide body.premium-page .site-scale-canvas,
html.site-scale-wide body.premium-product-page .site-scale-canvas {
  background: #000 !important;
}

/* Fixed UI (support, cookies, loader) — вне scale-canvas, строго к viewport */
#site-viewport-overlays {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  z-index: 10000;
  pointer-events: none;
  overflow: visible;
}

#site-viewport-overlays > * {
  pointer-events: auto;
}

/* Mobile header shell v2 — <=850px nav only (hero stays <=767) */
@media (max-width: 53.125rem) {
  .header .container {
    display: flex !important;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 0.625rem !important;
    grid-template-columns: none !important;
    grid-template-rows: none !important;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .header__left {
    display: flex;
    align-items: center;
    flex: 1 1 auto;
    min-width: 0;
    max-width: calc(100% - 3.25rem);
    width: auto !important;
    gap: clamp(6px, 2vw, 10px);
    flex-shrink: 1;
  }

  .header .logo.merary-brand {
    width: clamp(150px, 45vw, 190px) !important;
    min-height: 48px;
    gap: 8px !important;
    flex-shrink: 1;
    min-width: 0;
  }

  .header .city-select {
    min-width: 0;
    max-width: clamp(96px, 28vw, 140px);
    flex-shrink: 1;
    overflow: hidden;
  }

  .header .city-select__btn {
    padding: 6px 8px;
    font-size: 10px;
    max-width: 100%;
  }

  .header .city-select__btn strong {
    min-width: 0;
    max-width: 100%;
  }

  .header__center {
    display: none !important;
  }

  .header .nav,
  .header__center .nav {
    display: none !important;
  }

  .header__actions {
    display: none !important;
  }

  .header__menu-toggle {
    display: flex;
    flex: 0 0 auto;
    margin-left: auto;
  }
}

/* Product page reuses the homepage search. Hidden from 851px, where the desktop header stays unchanged. */
body.product-exact .home-search {
  display: none;
}

@media (max-width: 53.125rem) {
  body.product-exact .header .container,
  body.product-exact .home-search .container {
    width: 100% !important;
    max-width: calc(100vw - 2 * var(--gutter)) !important;
    margin-left: auto !important;
    margin-right: auto !important;
    padding-left: var(--gutter) !important;
    padding-right: var(--gutter) !important;
  }

  body.product-exact .home-search {
    display: block;
    padding: 4px 0 20px !important;
    position: sticky;
    top: 0;
    z-index: 300;
    background: transparent;
  }

  body.product-exact .home-search:has(#homeSearchSuggest:not([hidden])) {
    position: sticky;
    top: 0;
    z-index: 300;
  }

  body.product-exact .home-search__bar {
    position: relative;
    flex-wrap: nowrap;
    width: 100%;
    max-width: 100%;
    height: 45px;
    min-height: 45px;
    max-height: 45px;
    box-sizing: border-box;
    margin: 0;
    padding: 0 16px;
    gap: 10px;
    border-radius: 999px;
  }

  body.product-exact .home-search__bar:has(#homeSearchSuggest:not([hidden])) {
    overflow: visible;
  }

  body.product-exact .home-search__icon {
    width: 20px;
    height: 20px;
    color: #f05a86;
  }

  body.product-exact .home-search__input {
    height: 100%;
    font-size: 14px;
    line-height: 1.2;
    -webkit-appearance: none;
    appearance: none;
  }

  body.product-exact .home-search__submit {
    display: none;
  }

  body.product-exact .home-search .cx-search-suggest {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 10px);
    background: #fffdfc;
    border: 1px solid #eadfd9;
    border-radius: 18px;
    box-shadow: 0 20px 48px rgba(70, 40, 45, 0.14);
    z-index: 60;
    overflow: hidden;
    width: 100%;
  }

  body.product-exact .home-search .cx-search-suggest__list {
    max-height: calc(3 * 86px);
    overflow-y: auto;
    background: #fff;
  }

  body.product-exact .home-search .cx-search-suggest__item {
    width: 100%;
    min-height: 68px;
    display: grid;
    grid-template-columns: 48px 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 10px 14px;
    border: 0;
    border-bottom: 1px solid #f2e8e5;
    border-radius: 0;
    background: #fff;
    color: #221e1e;
    box-shadow: none;
    cursor: pointer;
    text-align: left;
    font: inherit;
    line-height: 1.25;
  }

  body.product-exact .home-search .cx-search-suggest__item img {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    object-fit: cover;
  }

  body.product-exact .home-search .cx-search-suggest__text {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
  }

  body.product-exact .home-search .cx-search-suggest__text strong {
    font-size: 14px;
    font-weight: 650;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  body.product-exact .home-search .cx-search-suggest__text small {
    color: #7d7572;
    font-size: 12px;
  }

  body.product-exact .home-search .cx-search-suggest__price {
    font-size: 14px;
    font-weight: 700;
    color: #c94d66;
    white-space: nowrap;
  }

  body.product-exact .product-section,
  body.product-exact .product-section.container {
    padding-top: 4px !important;
    width: 100% !important;
    max-width: calc(100vw - 2 * var(--gutter)) !important;
    margin-left: auto !important;
    margin-right: auto !important;
    padding-left: var(--gutter) !important;
    padding-right: var(--gutter) !important;
  }
}

/* Узкие телефоны ≤380px: бренд в шапке не сжимается ниже своего содержимого (иначе название MERARY заезжает
   на чип города); сжимается чип города (у него min-width:0 и обрезка по ширине). */
@media (max-width: 380px) {
  .header .logo.merary-brand {
    flex-shrink: 0;
  }
}

@media (max-width: 340px) {
  .header .logo.merary-brand {
    width: auto !important;
  }
}

/* ===== Этап 4: формы и зоны касания на телефонах и планшетах (≤850px) ===== */

/* Поля ввода ≥16px: на iOS при меньшем размере Safari приближает страницу при фокусе.
   Общее правило + точечные правки компонентов, у которых размер задан собственными селекторами. */
@media (max-width: 53.125rem) {
  html body input:is([type="text"], [type="search"], [type="email"], [type="tel"], [type="password"], [type="number"], [type="url"], :not([type])),
  html body select,
  html body textarea {
    font-size: 16px;
  }

  html body[data-page="home"] .home-search__input,
  html body .home-search__input,
  html body .price-field__control input,
  html body.cart-exact .promo-choice__input,
  html body.cart-exact .promo-row input,
  html body.shop-skin .field :is(input, select, textarea),
  html body.cabinet-skin .auth-fields .field input,
  html body.shop-skin .account-auth-form input,
  html body.product-exact .home-search__input,
  html body .email-row input {
    font-size: 16px;
  }

  :is(body.catalog-exact, .cx-admin-stage, #bestsellers) .cx-hero-search input {
    font-size: 16px;
  }

  /* Подсказка остаётся прежнего размера: на приближение iOS влияет только размер вводимого текста. */
  :is(body.catalog-exact, .cx-admin-stage, #bestsellers) .cx-hero-search input::placeholder {
    font-size: 13px;
  }
}

/* Зоны касания ≥44px без изменения внешнего вида: прозрачный псевдоэлемент шире самой кнопки.
   Только на узких экранах и на устройствах с касанием. */
@media (max-width: 53.125rem), (pointer: coarse) {
  .mcat-scroll__all,
  .product-messenger-btn,
  .footer__social,
  .qty-minus,
  .qty-plus,
  .remove-item,
  .reco-add,
  .back-link,
  #authSwitchBtn,
  label.checkbox,
  .section__link--btn,
  .mcn-subcats__all,
  .price-filter__preset,
  .occasion-chip,
  .auth-tabs button,
  .footer li > a {
    position: relative;
  }

  .cx-wish::after,
  .reco-fav::after,
  .reco-add::after,
  #productFavBtn::after,
  .product-messenger-btn::after,
  .footer__social::after {
    content: "";
    position: absolute;
    inset: -5px;
  }

  #merarySupportClose::after {
    content: "";
    position: absolute;
    inset: -6px -4px;
  }

  .qty-minus::after,
  .qty-plus::after {
    content: "";
    position: absolute;
    inset: -8px 0;
  }

  .remove-item::after {
    content: "";
    position: absolute;
    inset: -4px -12px;
  }

  .mcat-scroll__all::after {
    content: "";
    position: absolute;
    inset: -16px -8px;
  }

  .back-link::after {
    content: "";
    position: absolute;
    inset: -10px 0;
  }

  .section__link--btn::after,
  .mcn-subcats__all::after,
  .price-filter__preset::after,
  .occasion-chip::after,
  .auth-tabs button::after {
    content: "";
    position: absolute;
    inset: -5px 0;
  }

  .footer li > a::after {
    content: "";
    position: absolute;
    inset: -8px 0;
  }

  #authSwitchBtn::after,
  label.checkbox::after {
    content: "";
    position: absolute;
    inset: -11px 0;
  }
}
